MySQL: Support CAST(... AS ... ARRAY) syntax#2151
Merged
iffyio merged 1 commit intoapache:mainfrom Jan 23, 2026
Merged
Conversation
iffyio
approved these changes
Jan 22, 2026
Contributor
|
@mvzink could you take a look at the ci failures when you have some time? |
MySQL has a special case in `CAST` parsing where the type can be followed by `ARRAY`. This is only used for creating multi-valued indexes in InnoDB, so is only allowed in `CREATE TABLE` and other DDL statements when specifying keys. See the [docs]. Given those restrictions, we could be significantly more restrictive in parsing this, e.g. not parsing `ARRAY` unless we are in a key specification. Or, if there was such a thing as a suffix array type definition, we could parse it as a type. But as far as I know, that doesn't exist in any supported SQL dialects, and encountering `ARRAY` here is unambiguous. So it seemed simplest to be permissive and always parse it. The only downside I can see is we are now adding a field to `Expr::Cast`. [docs]: https://dev.mysql.com/doc/refman/8.4/en/cast-functions.html#function_cast
de2b2fa to
d9bb4d4
Compare
Contributor
Author
Done. Looks like another instance of |
ayman-sigma
pushed a commit
to sigmacomputing/sqlparser-rs
that referenced
this pull request
Feb 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MySQL has a special case in
CASTparsing where the type can be followed byARRAY. This is only used for creating multi-valued indexes in InnoDB, so is only allowed inCREATE TABLEand other DDL statements when specifying keys. See the docs.Given those restrictions, we could be significantly more restrictive in parsing this, e.g. not parsing
ARRAYunless we are in a key specification. Or, if there was such a thing as a suffix array type definition, we could parse it as a type. But as far as I know, that doesn't exist in any supported SQL dialects, and encounteringARRAYhere is unambiguous. So it seemed simplest to be permissive and always parse it. The only downside I can see is we are now adding a field toExpr::Cast.